package com.hbpu.encap.set;

import java.util.HashSet;
import java.util.Objects;

@SuppressWarnings({"all"})
public class HashSetExercise {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        hashSet.add(new Employee("mike", 25));
        hashSet.add(new Employee("jack", 21));
        hashSet.add(new Employee("rose", 32));
        hashSet.add(new Employee("mike", 25));

        System.out.println(hashSet);
    }
}

@SuppressWarnings({"all"})
class Employee {
    private String name;
    private int age;

    public Employee(String name, int age) {
        this.name = name;
        this.age = age;
    }

//    @Override
//    public int hashCode() {
//        return 100;
//    }
//
//    @Override
//    public boolean equals(Object obj) {
//        if (!(((Employee)obj).name == this.name && ((Employee)obj).age == this.age)) {
//            return false;
//        }
//        return true;
//    }


    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        Employee employee = (Employee) o;
        return age == employee.age && Objects.equals(name, employee.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}